import { defineStore } from 'pinia'
import { ref } from 'vue'

// 引入抽离出去的用户信息类型封装模块
import type { User } from '@/types/user'
// 创建仓库
export const useUserStore = defineStore(
  'cp-user',
  () => {
    // 定义数据
    const user = ref<User>()

    //   修改数据
    const setUser = (u: User): void => {
      user.value = u
    }

    //   删除数据
    const delUser = (): void => {
      user.value = undefined
    }

    // 存储回跳地址
    const returnUrl = ref('')
    const setReturnUrl = (url: string) => {
      returnUrl.value = url
    }

    return {
      user,
      setUser,
      delUser,
      returnUrl,
      setReturnUrl
    }
  },
  {
    persist: true
  }
)
